<?php

namespace app\api\controller;

//use app\api\model\OauthOrder;
use app\admin\model\Config as ConfigModel;
use bingher\ding\DingBot;
use think\Controller;
use app\common\model\OauthOrder;
use think\Db;
use app\common\controller\Send;

class Config extends Controller
{
    use Send;
    public function index()
    {

        //$rs = OauthCommission::transfers("20191010081543372371", "oMphd5U-Lrm62kTPmlIvJqq_JNDk", 72, '分享赚取佣金');
//        $rs = "test";
//        print_r($rs);
//        $msg = '';
//        $payResult = OauthOrde1r::orderNotify('oMphd5cU6rjfI2TDQjzD44J3NQ6w2', '20200601114454961589', '0.01', 1, '', $msg,null);
        $switch = Db::name('config')->where('setting_key','switch')->find();
        return self::sendResult(self::$okCode,   $switch);
    }
    public function demo() {

//        $demo = '[{"addresses":[],"displayName":"呵呵","emails":[],"events":[],"familyName":"呵","givenName":"呵","id":38,"note":"是个呵呵","phoneNumbers":[{"number":"23456789011","type":"MOBILE"}],"websites":[]},{"addresses":[],"displayName":"呵呵","emails":[],"events":[],"familyName":"呵","givenName":"呵","id":38,"note":"是个呵呵","phoneNumbers":[{"number":"23456789011","type":"MOBILE"}],"websites":[]}]';
    $demo  = '[[
 {
  "number": "23456789011",
  "displayName": "呵呵"
 },
 {
  "number": "23456789012",
  "displayName": "呵呵"
 },
 {
  "number": "23456789013",
  "displayName": "呵呵"
 },
]]';
    dump(json_decode($demo,true));
    }
    /**
     * PIN团
     */
    public function pintuan() {
        $oauthInfo = $this->oauthInfo;
        $data['pid'] = 0;
        $data['oauth_id'] = $oauthInfo['id'];
        $data['heads'] = 1;
        $data['group_num'] = 2;
        $data['class_id'] = 2;
        $data['groups_price'] = 1299;
        $data['price'] = 1200;
        $data['status'] = 0;
        $data['create_time'] = time();
        $data['failure_time'] = time();
        Db::name('bo_class_groups')->insert($data);
    }
    /*
     * 跑数据 看哪些用户买了课程
     */
    public function addClass() {

        $list  = Db::name('oauth')
            ->alias('c')
            ->order('id desc')
            ->limit(30)->select();

        foreach ($list as $k => $v) {
            $orderId = Db::name('oauth_order')->alias('o')
                ->join('oauth_order_class c', 'o.id=c.order_id')
                ->where('o.oauth_id',$v['id'])->find();
            if ($orderId) {
                $info = Db::name('oauth')->where('id',$orderId['oauth_id'])->update(['class_num'=>1]);
                echo Db::name('oauth')->getLastSql();exit;
                dump($info);exit;
                echo $orderId['oauth_id'].'<br/>';
            }
        }

    }
}
